#include "Reader.h"
#include <iostream>
#include <fstream>

#define SIZE_AVERAGE_FILE 20000
#define SIZE_MAX_LINE     500

Reader::Reader(void)
{
    m_sStream.reserve(SIZE_AVERAGE_FILE);
    m_nCursor = -1;
    //Marking as invalid
}

Reader::~Reader(void)
{
}

void Reader::gobble(std::string inFileName)
{
    m_sFileName = inFileName;
    std::ifstream xInFile(inFileName.c_str());
    char acLine[SIZE_MAX_LINE + 1];
    
    while(xInFile)
    {
        xInFile.getline(acLine, SIZE_MAX_LINE);
        if(xInFile)
        {
            m_sStream.append(acLine);
            m_sStream.push_back('\n');
        }
    }
        
    xInFile.close();
    
    m_nCursor = 0;
    //We gobble the entire file. Hence setting it to zero.
}

char Reader::spit(void)
{
    return m_sStream[m_nCursor++];
}

bool Reader::isFinished(void)
{
    if(m_nCursor >= (signed int)m_sStream.length())
    {
        return true;
    }
    return false;
}

std::string Reader::getStream(void)
{
    return m_sStream;
}